<template>
<<<<<<< HEAD
  <div class='container'>精选题库</div>
</template>

<script>
export default {}
=======
  <div class="dashboard-container">
    <div class="app-container">
      <el-card shadow="never">
        <!-- 搜索 -->
        <div class="addText">
          <span class="shuoming">说明：目前支持学科和关键字条件筛选</span>
          <el-button type="success" size="mini" @click="dump">新增试题</el-button>
        </div>

        <el-form :model="requestParameters" ref="requestParameters" label-width="80px">
          <el-row :gutter="20">
            <el-col :span="6">
              <el-form-item label="学科">
                <el-select class="filter-item" v-model="requestParameters.subjectID" @change="handleSubjectName">
                  <el-option v-for="(item, index) in subjectNameOption" :key="index" :label="item.label" :value="item.value"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="二级目录">
                <el-select class="filter-item" v-model="requestParameters.twoLevelDirectory">
                  <el-option v-for="(itemss, index) in twoLevelDirectory" :key="index" :label="itemss.label" :value="itemss.value"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="标签">
                <el-select class="filter-item" v-model="requestParameters.tags">
                  <el-option v-for="(item, index) in tags" :key="index" :label="item.label" :value="item.value"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="关键字">
                <el-input v-model="requestParameters.keyword" placeholder="根据题干搜索" clearable> </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="试题类型">
                <el-select class="filter-item" v-model="requestParameters.questionType" @keyup.enter="handleFilter" filterable>
                  <el-option v-for="item in questionTypes" :key="item.value" :label="item.label" :value="item.value"></el-option>
                </el-select>
              </el-form-item> </el-col
            ><el-col :span="6">
              <el-form-item label="难度">
                <el-select class="filter-item" v-model="requestParameters.difficulty" @keyup.enter="handleFilter" filterable>
                  <el-option v-for="item in difficulty" :key="item.value" :label="item.label" :value="item.value"></el-option>
                </el-select>
              </el-form-item> </el-col
            ><el-col :span="6">
              <el-form-item label="方向">
                <el-select class="filter-item" v-model="requestParameters.direction" @keyup.enter="handleFilter" filterable>
                  <el-option v-for="(item, index) in directions" :key="index" :label="item" :value="item"></el-option>
                </el-select>
              </el-form-item> </el-col
            ><el-col :span="6">
              <el-form-item label="录入人">
                <el-select class="filter-item" v-model="requestParameters.creatorID" @keyup.enter="handleFilter" filterable>
                  <el-option v-for="(item, index) in User" :key="index" :label="item.username" :value="item.id"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="题目备注">
                <el-input placeholder="请输入内容" clearable v-model="requestParameters.remarks"> </el-input>
              </el-form-item> </el-col
            ><el-col :span="6">
              <el-form-item label="企业简称">
                <el-input v-model="requestParameters.shortName" placeholder="请输入内容" clearable> </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="城市">
                <el-row :gutter="5">
                  <el-col :span="11">
                    <el-select class="filter-item" v-model="requestParameters.province" @keyup.enter="handleFilter" filterable @change="handleProvince">
                      <el-option v-for="(item, index) in provincelist" :key="index" :label="item" :value="item"></el-option> </el-select
                  ></el-col>
                  <el-col :span="11">
                    <el-select class="filter-item" v-model="requestParameters.city" @keyup.enter="handleFilter" filterable>
                      <el-option v-for="(item, index) in cityDatelist" :key="index" :label="item" :value="item"></el-option> </el-select
                  ></el-col>
                </el-row>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <div class="yes">
                <el-button size="small" @click="resetForm">清除</el-button>
                <el-button type="primary" size="small" @click="sousuo">搜索</el-button>
              </div>
            </el-col>
          </el-row>
        </el-form>
        <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
          <el-tab-pane label="全部" name="first"></el-tab-pane>

          <!-- 数据记录 -->
          <el-alert v-if="alertText !== ''" :title="alertText" type="info" class="alert" :closable="false" show-icon></el-alert>
          <!-- end -->
          <!-- 数据记录 -->
          <!-- 标签页 -->
          <el-tab-pane label="待审核" name="second"></el-tab-pane>
          <el-tab-pane label="已审核" name="third"></el-tab-pane>
          <el-tab-pane label="拒绝" name="fourth"></el-tab-pane>
        </el-tabs>
        <!-- 数据列表 -->
        <el-table :data="dataList" fit highlight-current-row style="width: 100%" size="small">
          <el-table-column align="center" label="试题编号" width="120">
            <template slot-scope="scope">
              <span>{{ scope.row.number }}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="学科">
            <template slot-scope="scope">
              <span>{{ scope.row.subject }}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="目录">
            <template slot-scope="scope">
              <span>{{ scope.row.catalog }}</span>
            </template>
          </el-table-column>
          <el-table-column label="题型">
            <template slot-scope="scope">
              <span>{{ scope.row.questionType }}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="录入日期" width="220">
            <template slot-scope="scope">
              <span>{{ scope.row.addDate | parseTimeByString() }}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="难度">
            <template slot-scope="scope">
              <span v-if="scope.row.difficulty === 1">简单</span>
              <span v-else-if="scope.row.difficulty === 2">一般</span>
              <span v-else>困难</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="录入人">
            <template slot-scope="scope">
              <span>{{ scope.row.creator }}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="审核状态">
            <template slot-scope="scope">
              <span v-if="scope.row.chkState === 0">待审核</span>
              <span v-if="scope.row.chkState === 1">已审核</span>
              <span v-if="scope.row.chkState === 2">已拒绝</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="审核意见">
            <template slot-scope="scope">
              <span>{{ scope.row.chkRemarks }}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="审核人">
            <template slot-scope="scope">
              <span>{{ scope.row.creator }}</span>
            </template>
          </el-table-column>
          <!-- 操作按钮 -->
          <el-table-column fixed="right" align="center" label="操作" width="210" class-name="fixed-width">
            <template slot-scope="scope">
              <el-button type="text" size="mini" @click="previewDetail(scope.row)">预览</el-button
              ><el-button type="text" size="mini" @click="handleChangeShen(scope.row.id)" :disabled="scope.row.chkState > 0">审核</el-button
              ><el-button type="text" size="mini" @click="handleChange(scope.row.id)">修改</el-button>
              <el-button type="text" size="mini" @click="handleStatus(scope.row)">
                <span v-if="scope.row.publishState == 0">上架</span>
                <span v-else>下架</span>
              </el-button>
              <el-button v-if="scope.row.status != 'deleted'" size="mini" type="text" @click="removeUser(scope.row.id)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- end -->
        <!-- 分页 -->
        <div class="block">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="requestParameters.page"
            :page-sizes="[2, 5, 10, 20]"
            :page-size="requestParameters.pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
          >
          </el-pagination>
        </div>
        <!-- end -->
      </el-card>
    </div>
    <!-- 审核 -->
    <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
      <el-radio-group v-model="radio">
        <el-radio :label="1">通过</el-radio>
        <el-radio :label="2">拒绝</el-radio>
      </el-radio-group>
      <el-input class="textarea" type="textarea" :rows="2" placeholder="请输入审核意见" v-model="textarea" />
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="audit">确 定</el-button>
      </span>
    </el-dialog>
    <preview ref="previewRef" :preview-data="previewData" :daanjiexi-a="daanjiexi" />
  </div>
</template>

<script>
import {
  list,
  remove,
  detail,
  disabled,
  choice,
  choicePublish,
  update,
  choiceCheck //审核
} from '@/api/hmmm/questions'
import { simple as subjects } from '@/api/hmmm/subjects'
import { simple as twoCatalog } from '@/api/hmmm/directorys'
import { provinces, citys } from '@/api/hmmm/citys.js'
import { simple as tagsSimple } from '@/api/hmmm/tags.js'
import { simple as userSimple } from '@/api/base/users.js'
import { simple as directorysSimple } from '@/api/hmmm/directorys.js'
import Dialog from './../components/companys-add'
import Check from './../components/questions-check'
import preview from '../components/questions-preview'
import { difficulty, questionType, direction, chkType, publishType } from '@/api/hmmm/constants.js'
export default {
  name: 'CompanysList',
  components: {
    Dialog,
    Check,
    preview
  },
  data() {
    return {
      total: null,
      dataList: [],
      listLoading: true,
      alertText: '',
      sunPage: {},
      dialogVisible: false,
      // 提交的数据
      requestParameters: {
        page: 1,
        pagesize: 10,
        subjectID: null, //学科
        keyword: ''
        // catalogID: '',
        // tags: '', //标签
        // difficulty: '',
        // questionType: '',
        // keyword: '',
        // direction: '', // 方向
        // creatorID: '', // 录入人
        // chkState: '', //审核状态
        // remarks: '', //题目备注
        // shortName: '', //简称
        // province: '', // 省份
        // city: '' //城市
      },
      textarea: '', //文本框
      radio: 1,
      activeName: 'first',
      tags: [], // 接口获取的标签数组
      difficulty: difficulty, // 难度
      questionTypes: questionType, // 类型
      directions: direction, // 方向
      previewData: {},
      daanjiexi: {},
      // 城市
      provincelist: [],
      cityDatelist: [],
      subjectNameOption: [], // 接口获取学科
      twoLevelDirectory: [], //二级目录
      remarks: '', //题目备注
      User: '' //录入人
    }
  },
  computed: {},
  methods: {
    // 初始数据
    initialDate() {
      // 读取数据
      this.getList()
      this.getUser()
    },

    // 获取列表数据
    async getList() {
      this.listLoading = true
      const { data: res } = await choice(this.requestParameters)
      // 获取数据给dataList
      this.dataList = res.items
      // 获取总条数
      this.total = res.counts
      this.alertText = `共 ${this.total} 条记录`
      this.listLoading = false

      //学科
      const { data } = await subjects()
      //获取数据给subject

      // console.log(data)
      this.subjectNameOption = data
      this.getCityData()
    },
    //搜索
    sousuo() {
      this.getList()
    },
    //学科改变事件
    async handleSubjectName(e) {
      const { data: res } = await directorysSimple({
        subjectID: e
      })
      const { data } = await tagsSimple({
        subjectID: e
      })
      this.twoLevelDirectory = res
      this.tags = data
    },
    // 获取录入人
    async getUser(params) {
      const { data: res } = await userSimple()
      // console.log(res)
      this.User = res
    },
    // 标签页
    handleClick(tab) {
      this.requestParameters.chkState = tab.index > 0 ? tab.index - 1 : null
      this.getList()
    },
    // 预览
    async previewDetail(val) {
      const { data: res } = await detail(val)
      this.daanjiexi = res
      this.previewData = val
      this.$refs.previewRef.timuyulan()
    },
    // 上架/下架
    handleStatus(val) {
      console.log(val)
      var status = ''
      val.publishState === 1 ? (status = '上架') : (status = '下架')

      this.$confirm('确认要' + status + '这道题目吗', '提示', {
        type: 'warning'
      })
        .then(async () => {
          console.log(data)
          val.publishState === 1 ? (val.publishState = 0) : (val.publishState = 1)
          var data = {
            id: val.id,
            publishState: val.publishState
          }
          await choicePublish(data)
            .then((response) => {
              this.$message.success('成功' + status + '!')
              this.getList()
            })
            .catch((response) => {
              this.$message.error(status + '操作失败!')
            })
        })
        .catch(() => {
          this.$message.info('已取消操作!')
        })
    },
    // 审核___________________________
    handleChangeShen(id) {
      this.dialogVisible = true
      this.auditId = id
    },
    //_________________________
    // 跳录入
    dump() {
      this.$router.push('/questions/new')
    },
    // 修改
    handleChange(id) {
      // this.$router.push(`/questions/new?id=${id}&type=1`)
      this.$router.push({ name: 'questions-new', params: { id: id, type: 1 } })
    },

    // 清除
    resetForm() {
      this.requestParameters = {}
    },
    // 搜索信息
    handleFilter() {
      this.requestParameters.page = 1
      this.getList(this.requestParameters)
    },
    // 每页显示信息条数
    handleSizeChange(val) {
      this.requestParameters.pagesize = val
      if (this.requestParameters.page === 1) {
        this.getList()
      }
    },
    // 进入某一页
    handleCurrentChange(val) {
      this.requestParameters.page = val
      this.getList()
    },

    // **********************************
    // 搜索的项目
    // 添加、编辑之后表单清空
    query() {
      this.formData = {}
    },
    // 窗口操作**********************************
    // 编辑
    // 删除
    removeUser(user) {
      this.$confirm('此操作将永久删除该题目, 是否继续?', '提示', {
        type: 'warning'
      })
        .then(async () => {
          await remove({ id: user })
            .then((response) => {
              this.$message.success('成功删除了用户' + '!')
              this.dataList.splice(user, 1)
              this.getList(this.requestParameters)
            })
            .catch((response) => {
              this.$message.error('删除失败!')
            })
        })
        .catch(() => {
          this.$message.info('已取消操作!')
        })
    },
    // 获取省
    getCityData: function () {
      this.provincelist = provinces
    },
    // 选省获取到市
    handleProvince: function (e) {
      this.cityDatelist = citys(e)
      // console.log(this.cityDatelist)
    },
    // 审核
    audit() {
      if (this.textarea.length === 0) {
        this.$message.warning('请输入意见')
      } else {
        choiceCheck({ chkState: this.radio, chkRemarks: this.textarea, id: this.auditId }).then((response) => {
          if (response.data.success) {
            this.$message.success('成功')
            this.dialogVisible = false
            this.getList()
          }
        })
      }
    }
  },
  // 创建完毕状态
  created() {
    this.initialDate()

    // this.listData()
  }
}
>>>>>>> 99b581ad90efc8af6413e4097d13ec8f4855db58
</script>

<style scoped lang='less'></style>
